/**
 * @project lauwsys
 * @author Christian Teguh
 * @created 22 Okt 2011 05.17.04
 *
 */
package com.chimoz.lauwsys.mvc;

import javax.inject.Inject;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.validation.BindingResult;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.ModelAndView;

import com.chimoz.lauwsys.domain.Brand;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( locations = {"classpath:db/lauwsys-jpa.xml", "file:src/main/webapp/WEB-INF/spring/lauwsys-servlet.xml"} )
public class HomeControllerTestUnit {

	@Inject
	private ApplicationContext applicationContext;
	
	private MockHttpServletRequest request;
	private MockHttpServletResponse response;
	private HandlerAdapter handlerAdapter;
	private HomeController homeController;
	
	
	@Before
	public void setUp() {
		request = new MockHttpServletRequest();
	    response = new MockHttpServletResponse();
	    handlerAdapter = applicationContext.getBean(HandlerAdapter.class);
	    // I could get the controller from the context here
//	    homeController = new HomeController();
	}
	
	
	
	
	
//	@Test
//    public void testGet() throws Exception {
//       request.setMethod("GET");
//       final ModelAndView mav = handlerAdapter.handle(request, response, controller);
//       assertViewName(mav, null);
//       assertAndReturnModelAttributeOfType(mav, "myForm", MyForm.class);
//    }
//
//    @Test
//    public void testPost() throws Exception {
//       request.setMethod("POST");
//       request.addParameter("firstName", "  Anthony  ");
//       final ModelAndView mav = handlerAdapter.handle(request, response, controller);
//       final MyForm myForm = assertAndReturnModelAttributeOfType(mav, "myForm", MyForm.class);
//       assertEquals("Anthony", myForm.getFirstName());
//
//       /* if myForm is not valid */
//       assertViewName(mav, null);
//       final BindingResult errors = assertAndReturnModelAttributeOfType(mav,
//               "org.springframework.validation.BindingResult.myForm",
//               BindingResult.class);
//       assertTrue(errors.hasErrors());
//    }
}
